package com.suneast.suneaststore.ui.fragments;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.suneast.suneaststore.ui.dialog.CancelConfirmDialog;

public abstract class BaseFragmentWithDialog extends BaseFragment implements CancelConfirmDialog.ConfirmBtnClickListener {
    private CancelConfirmDialog dialog;

    protected final static int STYLE_DEFAULT = 0;
    protected final static int HIDE_DIALOG_CANCEL = 2;
    protected final static int HIDE_DIALOG_CONFIRM = 1;
    protected final static int HIDE_DIALOG_TITLE = 4;

    protected void onDialogConfirm() {
        hideDialog();
    }

    protected void onDialogCancel() {
        hideDialog();
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        dialog = new CancelConfirmDialog();
        dialog.setListener(this);
        return super.onCreateView(inflater, container, savedInstanceState);
    }

    /**
     * 设置dialog样式（可选，默认为0显示所有）
     * @param flag 立flag
     */
    protected final void setDialogStyle(int flag) {
        dialog.setStyle(flag);
    }

    /**
     * 设置dialog标题（可选， 默认为 "提示"）
     * @param title 标题
     */
    protected final void setDialogTitle(String title) {
        dialog.setTitle(title);
    }

    /**
     * 设置dialog内容（必须设置，默认为空）
     * @param content 内容
     */
    protected final void setDialogContent(String content) {
        dialog.setContent(content);
    }

    /**
     * 显示dialog，一个方法专心一件事
     */
    protected final void showDialog() {
        dialog.show(getSupportDelegate().getActivity().getSupportFragmentManager(), "");
    }

    /**
     * 隐藏dialog，一个方法专心一件事
     */
    protected final void hideDialog() {
        dialog.dismiss();
    }

    @Override
    public void onConfirm() {
        onDialogConfirm();
    }

    @Override
    public void onCancel() {
        onDialogCancel();
    }
}
